<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>tango.net.http.HttpClient</title>
  <link href="./css/style.css" rel="stylesheet" type="text/css"/>
  <!-- <link href="./img/icon.png" rel="icon" type="image/png"/> -->
  <script type="text/javascript" src="./js/jquery.js"></script>
  <script type="text/javascript" src="./js/modules.js"></script>
  <script type="text/javascript" src="./js/quicksearch.js"></script>
  <script type="text/javascript" src="./js/navigation.js"></script>
  <!--<script type="text/javascript" src="./js/jquery.treeview.js"></script>-->
  <script type="text/javascript">
    var g_moduleFQN = "tango.net.http.HttpClient";
  </script>
  
</head>
<body>
<div id="content">
  <h1><a href="./htmlsrc/tango.net.http.HttpClient.html" class="symbol">tango.net.http.HttpClient</a></h1>
  
<p class="sec_header">License:</p>BSD style: see <a href="http://www.dsource.org/projects/tango/wiki/LibraryLicense">license.txt</a>
<p class="sec_header">Version:</p>Initial release: April 2004      
                        Outback release: December 2006
<p class="sec_header">Author:</p>Kris    - original module
<p class="sec_header">Author:</p>h3r3tic - fixed a number of Post issues and
                                  bugs in the 'params' construction
<p class="bl"/>
        Redirection handling guided via 
                    http://ppewww.ph.gla.ac.uk/~flavell/www/post-redirect.html
<dl>
<dt class="decl">class <a class="symbol _class" name="HttpClient" href="./htmlsrc/tango.net.http.HttpClient.html#L80" kind="class" beg="80" end="690">HttpClient</a>; <a title="Permalink to this symbol" href="#HttpClient" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L80">#</a></dt>
<dd class="ddef">
<div class="summary">Supports the basic needs of a client making requests of an HTTP
        server. The following is an example of how this might be used:</div>
<pre class="d_code">
<span class="lc">// callback for client reader</span>
<span class="k">void</span> <span class="i">sink</span> (<span class="k">char</span>[] <span class="i">content</span>)
{
        <span class="i">Stdout</span>.<span class="i">put</span> (<span class="i">content</span>);
}

<span class="lc">// create client for a GET request</span>
<span class="k">auto</span> <span class="i">client</span> = <span class="k">new</span> <span class="i">HttpClient</span> (<span class="i">HttpClient</span>.<span class="i">Get</span>, <span class="sl">"http://www.yahoo.com"</span>);

<span class="lc">// make request</span>
<span class="i">client</span>.<span class="i">open</span> ();

<span class="lc">// check return status for validity</span>
<span class="k">if</span> (<span class="i">client</span>.<span class="i">isResponseOK</span>)
   {
   <span class="lc">// extract content length</span>
   <span class="k">auto</span> <span class="i">length</span> = <span class="i">client</span>.<span class="i">getResponseHeaders</span>.<span class="i">getInt</span> (<span class="i">HttpHeader</span>.<span class="i">ContentLength</span>, <span class="k">uint</span>.<span class="i">max</span>);

   <span class="lc">// display all returned headers</span>
   <span class="i">Stdout</span>.<span class="i">put</span> (<span class="i">client</span>.<span class="i">getResponseHeaders</span>);

   <span class="lc">// display remaining content</span>
   <span class="i">client</span>.<span class="i">read</span> (&amp;<span class="i">sink</span>, <span class="i">length</span>);
   }
<span class="k">else</span>
   <span class="i">Stderr</span>.<span class="i">put</span> (<span class="i">client</span>.<span class="i">getResponse</span>);

<span class="i">client</span>.<span class="i">close</span> ();
</pre>
<p class="bl"/>
        See modules HttpGet and HttpPost for simple wrappers instead.
<dl>
<dt class="decl"><a class="symbol _ctor" name="HttpClient.this" href="./htmlsrc/tango.net.http.HttpClient.html#L145" kind="ctor" beg="145" end="148">this</a><span class="params">(RequestMethod <em>method</em>, char[] <em>url</em>)</span>; <a title="Permalink to this symbol" href="#HttpClient.this" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L145">#</a></dt>
<dd class="ddef">
<div class="summary">Create a client for the given URL. The argument should be
                fully qualified with an "http:" or "https:" scheme, or an
                explicit port should be provided.</div></dd>
<dt class="decl"><a class="symbol _ctor" name="HttpClient.this:2" href="./htmlsrc/tango.net.http.HttpClient.html#L158" kind="ctor" beg="158" end="182">this</a><span class="params">(RequestMethod <em>method</em>, Uri <em>uri</em>)</span>; <a title="Permalink to this symbol" href="#HttpClient.this:2" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L158">#</a></dt>
<dd class="ddef">
<div class="summary">Create a client with the provided Uri instance. The Uri should 
                be fully qualified with an "http:" or "https:" scheme, or an
                explicit port should be provided.</div></dd>
<dt class="decl">HttpHeadersView <a class="symbol _function" name="HttpClient.getResponseHeaders" href="./htmlsrc/tango.net.http.HttpClient.html#L190" kind="function" beg="190" end="193">getResponseHeaders</a><span class="params">()</span>; <a title="Permalink to this symbol" href="#HttpClient.getResponseHeaders" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L190">#</a></dt>
<dd class="ddef">
<div class="summary">Get the current input headers, as returned by the host request.</div></dd>
<dt class="decl">HttpHeaders <a class="symbol _function" name="HttpClient.getRequestHeaders" href="./htmlsrc/tango.net.http.HttpClient.html#L202" kind="function" beg="202" end="205">getRequestHeaders</a><span class="params">()</span>; <a title="Permalink to this symbol" href="#HttpClient.getRequestHeaders" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L202">#</a></dt>
<dd class="ddef">
<div class="summary">Gain access to the request headers. Use this to add whatever
                headers are required for a request.</div></dd>
<dt class="decl">HttpParams <a class="symbol _function" name="HttpClient.getRequestParams" href="./htmlsrc/tango.net.http.HttpClient.html#L216" kind="function" beg="216" end="219">getRequestParams</a><span class="params">()</span>; <a title="Permalink to this symbol" href="#HttpClient.getRequestParams" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L216">#</a></dt>
<dd class="ddef">
<div class="summary">Gain access to the request parameters. Use this to add x=y
                style parameters to the request. These will be appended to
                the request assuming the original Uri does not contain any
                of its own.</div></dd>
<dt class="decl">UriView <a class="symbol _function" name="HttpClient.getUri" href="./htmlsrc/tango.net.http.HttpClient.html#L227" kind="function" beg="227" end="230">getUri</a><span class="params">()</span>; <a title="Permalink to this symbol" href="#HttpClient.getUri" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L227">#</a></dt>
<dd class="ddef">
<div class="summary">Return the Uri associated with this client</div></dd>
<dt class="decl">ResponseLine <a class="symbol _function" name="HttpClient.getResponse" href="./htmlsrc/tango.net.http.HttpClient.html#L240" kind="function" beg="240" end="243">getResponse</a><span class="params">()</span>; <a title="Permalink to this symbol" href="#HttpClient.getResponse" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L240">#</a></dt>
<dd class="ddef">
<div class="summary">Return the response-line for the latest request. This takes 
                the form of "version status reason" as defined in the HTTP
                RFC.</div></dd>
<dt class="decl">int <a class="symbol _function" name="HttpClient.getStatus" href="./htmlsrc/tango.net.http.HttpClient.html#L251" kind="function" beg="251" end="254">getStatus</a><span class="params">()</span>; <a title="Permalink to this symbol" href="#HttpClient.getStatus" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L251">#</a></dt>
<dd class="ddef">
<div class="summary">Return the HTTP status code set by the remote server</div></dd>
<dt class="decl">bool <a class="symbol _function" name="HttpClient.isResponseOK" href="./htmlsrc/tango.net.http.HttpClient.html#L262" kind="function" beg="262" end="265">isResponseOK</a><span class="params">()</span>; <a title="Permalink to this symbol" href="#HttpClient.isResponseOK" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L262">#</a></dt>
<dd class="ddef">
<div class="summary">Return whether the response was OK or not</div></dd>
<dt class="decl">void <a class="symbol _function" name="HttpClient.addCookie" href="./htmlsrc/tango.net.http.HttpClient.html#L273" kind="function" beg="273" end="276">addCookie</a><span class="params">(Cookie <em>cookie</em>)</span>; <a title="Permalink to this symbol" href="#HttpClient.addCookie" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L273">#</a></dt>
<dd class="ddef">
<div class="summary">Add a cookie to the outgoing headers</div></dd>
<dt class="decl">void <a class="symbol _function" name="HttpClient.close" href="./htmlsrc/tango.net.http.HttpClient.html#L285" kind="function" beg="285" end="293">close</a><span class="params">()</span>; <a title="Permalink to this symbol" href="#HttpClient.close" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L285">#</a></dt>
<dd class="ddef">
<div class="summary">Close all resources used by a request. You must invoke this 
                between successive open() calls.</div></dd>
<dt class="decl">void <a class="symbol _function" name="HttpClient.reset" href="./htmlsrc/tango.net.http.HttpClient.html#L301" kind="function" beg="301" end="306">reset</a><span class="params">()</span>; <a title="Permalink to this symbol" href="#HttpClient.reset" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L301">#</a></dt>
<dd class="ddef">
<div class="summary">Reset the client such that it is ready for a new request.</div></dd>
<dt class="decl">void <a class="symbol _function" name="HttpClient.setRequest" href="./htmlsrc/tango.net.http.HttpClient.html#L314" kind="function" beg="314" end="317">setRequest</a><span class="params">(RequestMethod <em>method</em>)</span>; <a title="Permalink to this symbol" href="#HttpClient.setRequest" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L314">#</a></dt>
<dd class="ddef">
<div class="summary">Set the request method</div></dd>
<dt class="decl">void <a class="symbol _function" name="HttpClient.setVersion" href="./htmlsrc/tango.net.http.HttpClient.html#L325" kind="function" beg="325" end="330">setVersion</a><span class="params">(Version <em>v</em>)</span>; <a title="Permalink to this symbol" href="#HttpClient.setVersion" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L325">#</a></dt>
<dd class="ddef">
<div class="summary">Set the request version</div></dd>
<dt class="decl">void <a class="symbol _function" name="HttpClient.enableRedirect" href="./htmlsrc/tango.net.http.HttpClient.html#L338" kind="function" beg="338" end="341">enableRedirect</a><span class="params">(bool <em>yes</em>)</span>; <a title="Permalink to this symbol" href="#HttpClient.enableRedirect" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L338">#</a></dt>
<dd class="ddef">
<div class="summary">enable/disable the internal redirection suppport</div></dd>
<dt class="decl">void <a class="symbol _function" name="HttpClient.setTimeout" href="./htmlsrc/tango.net.http.HttpClient.html#L349" kind="function" beg="349" end="352">setTimeout</a><span class="params">(float <em>interval</em>)</span>; <a title="Permalink to this symbol" href="#HttpClient.setTimeout" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L349">#</a></dt>
<dd class="ddef">
<div class="summary">set timeout period for read operation</div></dd>
<dt class="decl">void <a class="symbol _function" name="HttpClient.keepAlive" href="./htmlsrc/tango.net.http.HttpClient.html#L360" kind="function" beg="360" end="363">keepAlive</a><span class="params">(bool <em>yes</em>)</span>; <a title="Permalink to this symbol" href="#HttpClient.keepAlive" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L360">#</a></dt>
<dd class="ddef">
<div class="summary">Control keepalive option</div></dd>
<dt class="decl">void <a class="symbol _function" name="HttpClient.encodeUri" href="./htmlsrc/tango.net.http.HttpClient.html#L371" kind="function" beg="371" end="374">encodeUri</a><span class="params">(bool <em>yes</em>)</span>; <a title="Permalink to this symbol" href="#HttpClient.encodeUri" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L371">#</a></dt>
<dd class="ddef">
<div class="summary">Control Uri output encoding</div></dd>
<dt class="decl">IBuffer <a class="symbol _function" name="HttpClient.open" href="./htmlsrc/tango.net.http.HttpClient.html#L385" kind="function" beg="385" end="388">open</a><span class="params">(IBuffer <em>buffer</em> = null)</span>; <a title="Permalink to this symbol" href="#HttpClient.open" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L385">#</a></dt>
<dd class="ddef">
<div class="summary">Make a request for the resource specified via the constructor,
                using the specified timeout period (in milli-seconds).The 
                return value represents the input buffer, from which all
                returned headers and content may be accessed.</div></dd>
<dt class="decl">IBuffer <a class="symbol _function" name="HttpClient.open:2" href="./htmlsrc/tango.net.http.HttpClient.html#L400" kind="function" beg="400" end="403">open</a><span class="params">(Pump <em>pump</em>, IBuffer <em>buffer</em> = null)</span>; <a title="Permalink to this symbol" href="#HttpClient.open:2" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L400">#</a></dt>
<dd class="ddef">
<div class="summary">Make a request for the resource specified via the constructor,
                using a callback for pumping additional data to the host. This 
                defaults to a three-second timeout period. The return value 
                represents the input buffer, from which all returned headers 
                and content may be accessed.</div></dd>
<dt class="decl">void <a class="symbol _function" name="HttpClient.read" href="./htmlsrc/tango.net.http.HttpClient.html#L574" kind="function" beg="574" end="593">read</a><span class="params">(void delegate (void[]) <em>sink</em>, long <em>len</em> = long.max)</span>; <a title="Permalink to this symbol" href="#HttpClient.read" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L574">#</a></dt>
<dd class="ddef">
<div class="summary">Read the content from the returning input stream, up to a
                maximum length, and pass content to the given sink delegate
                as it arrives.</div>
Exits when length bytes have been processed, or an Eof is
                seen on the stream.</dd>
<dt class="decl">IBuffer <a class="symbol _function" name="HttpClient.redirectPost" href="./htmlsrc/tango.net.http.HttpClient.html#L604" kind="function" beg="604" end="629">redirectPost</a><span class="params">(Pump <em>pump</em>, IBuffer <em>input</em>, int <em>status</em>)</span>; <a title="Permalink to this symbol" href="#HttpClient.redirectPost" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L604">#</a></dt>
<dd class="ddef">
<div class="summary">Handle redirection of Post
                
                Guidance for the default behaviour came from this page: 
                http://ppewww.ph.gla.ac.uk/~flavell/www/post-redirect.html</div></dd>
<dt class="decl">bool <a class="symbol _function" name="HttpClient.canRepost" href="./htmlsrc/tango.net.http.HttpClient.html#L641" kind="function" beg="641" end="644">canRepost</a><span class="params">(uint <em>status</em>)</span>; <a title="Permalink to this symbol" href="#HttpClient.canRepost" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L641">#</a></dt>
<dd class="ddef">
<div class="summary">Handle user-notification of Post redirection. This should
                be overridden appropriately.</div>
Guidance for the default behaviour came from this page: 
                http://ppewww.ph.gla.ac.uk/~flavell/www/post-redirect.html</dd>
<dt class="decl">SocketConduit <a class="symbol _function" name="HttpClient.createSocket" href="./htmlsrc/tango.net.http.HttpClient.html#L652" kind="function" beg="652" end="655">createSocket</a><span class="params">()</span>; <span class="attrs">[<span class="prot">protected</span>]</span> <a title="Permalink to this symbol" href="#HttpClient.createSocket" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L652">#</a></dt>
<dd class="ddef">
<div class="summary">Overridable socket factory, for use with HTTPS and so on</div></dd>
<dt class="decl">IBuffer <a class="symbol _function" name="HttpClient.open:3" href="./htmlsrc/tango.net.http.HttpClient.html#L680" kind="function" beg="680" end="689">open</a><span class="params">(RequestMethod <em>method</em>, Pump <em>pump</em>, IBuffer <em>input</em>)</span>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#HttpClient.open:3" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L680">#</a></dt>
<dd class="ddef">
<div class="summary">Make a request for the resource specified via the constructor
                using the specified timeout period (in micro-seconds), and a
                user-defined callback for pumping additional data to the host.
                The callback would be used when uploading data during a 'put'
                operation (or equivalent). The return value represents the 
                input buffer, from which all returned headers and content may 
                be accessed.</div>
Note that certain request-headers may generated automatically
                if they are not present. These include a Host header and, in
                the case of Post, both ContentType &amp; ContentLength for a query
                type of request. The latter two are *not* produced for Post
                requests with 'pump' specified ~ when using 'pump' to output
                additional content, you must explicitly set your own headers.
<p class="bl"/>
                Note also that IOException instances may be thrown. These 
                should be caught by the client to ensure a close() operation
                is always performed</dd></dl></dd>
<dt class="decl">class <a class="symbol _class" name="ResponseLine" href="./htmlsrc/tango.net.http.HttpClient.html#L699" kind="class" beg="699" end="756">ResponseLine</a> : HttpTriplet; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#ResponseLine" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L699">#</a></dt>
<dd class="ddef">
<div class="summary">Class to represent an HTTP response-line</div>
<dl>
<dt class="decl">void <a class="symbol _function" name="ResponseLine.test" href="./htmlsrc/tango.net.http.HttpClient.html#L711" kind="function" beg="711" end="722">test</a><span class="params">()</span>; <a title="Permalink to this symbol" href="#ResponseLine.test" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L711">#</a></dt>
<dd class="ddef">
<div class="summary">test the validity of these tokens</div></dd>
<dt class="decl">char[] <a class="symbol _function" name="ResponseLine.getVersion" href="./htmlsrc/tango.net.http.HttpClient.html#L730" kind="function" beg="730" end="733">getVersion</a><span class="params">()</span>; <a title="Permalink to this symbol" href="#ResponseLine.getVersion" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L730">#</a></dt>
<dd class="ddef">
<div class="summary">Return HTTP version</div></dd>
<dt class="decl">char[] <a class="symbol _function" name="ResponseLine.getReason" href="./htmlsrc/tango.net.http.HttpClient.html#L741" kind="function" beg="741" end="744">getReason</a><span class="params">()</span>; <a title="Permalink to this symbol" href="#ResponseLine.getReason" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L741">#</a></dt>
<dd class="ddef">
<div class="summary">Return reason text</div></dd>
<dt class="decl">int <a class="symbol _function" name="ResponseLine.getStatus" href="./htmlsrc/tango.net.http.HttpClient.html#L752" kind="function" beg="752" end="755">getStatus</a><span class="params">()</span>; <a title="Permalink to this symbol" href="#ResponseLine.getStatus" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.net.http.HttpClient.html#L752">#</a></dt>
<dd class="ddef">
<div class="summary">Return status integer</div></dd></dl></dd></dl>
</div>
<div id="footer">
  <p>Copyright (c) 2004 Kris Bell. All rights reserved</p>
  <p>Page generated by <a href="http://code.google.com/p/dil">dil</a> on Fri Dec 26 04:03:56 2008. Rendered by <a href="http://code.google.com/p/dil/wiki/Kandil">kandil</a>.</p>
</div>
</body>
</html>